<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/8/20
 * Time: 9:40
 */

namespace app\admin\controller;


use app\service\IGeTuiService;
use app\service\MemberService;
use app\service\SmsCode;
use Redis\Redis;
use think\Controller;
use think\Db;


class Demo extends Controller
{
    function teamFollow()
    {
//        # 查询团队领导人
//        $team = Db::table('team')->where(array('is_fake' => 1))->order('id asc')->select();
//        dump($team);
//        foreach ($team as $k => $v) {
//            # 查询他所对应的所有下级
//            $subordinate = getsTeamChild($v['member_code']);
//            dump($v['member_code']);
//            dump($subordinate);
//            dump('<hr/>');
//        }
        $subordinate = getsTeamChild('BA239715');

        foreach ($subordinate as $k => $v) {
            $subordinate[$k] = "'" . $v . "'";
        }
        $subordinates = implode(',', $subordinate);
        dump($subordinates);
//        Db::table('member')->where("code in (" . $subordinates . ")")->update(array('team_id' => 2));
        dump(Db::table('member')->field('code,team_id')->where("code in (" . $subordinates . ")")->select());
//        foreach ($subordinate as $k => $v) {
//            MemberService::changeRedis($v);
//        }

    }

    function changeRedis()
    {
        $info = Db::table('member')->field('code')->select();
        foreach ($info as $k => $v) {
            MemberService::changeRedis($v['code']);
        }
        dump(123);
    }

    function robbey()
    {
        $redis = new Redis();
        $robbingFive = $redis->hGetJson('robbingFive', 'AB734275');
        dump($robbingFive);
        $a = $robbingFive = Db::table('log_rob')
            ->field('distinct robbed_code')
            ->where(array('member_code' => 'DA199282'))
            ->where("date(create_time) = '2020-09-11'")
//               ->group('robber_code')
            ->select();
        dump($a);
    }

    function geTui()
    {
        $a = new IGeTuiService();
        $b = $a->pushMessageToSingle('141b3c5e4f0ea0bfc3e1792932702272');
        dump($b);
    }

    function getUserStatus()
    {
        $a = new IGeTuiService();
        $b = $a->getUserStatus(input('get.code'));
        dump($b);
    }

    function demo()
    {
        $downloadNum = Db::connect("db_config2")->table("download_info")
            ->where([['date_format(time,"%Y-%m-%d")', '=', date('Y-m-10')]])
//            ->where('time','between',[date('Y-m-d 00:00:00'),date('Y-m-d 23:59:59')])
            ->select();
        dump($downloadNum);
        die;
        $a = new IGeTuiService();
        $content = '这是哪里?';
        $title = '红包来了';
        $text = '这是消息内容';
        $code = 'gb340177';
        $rep = $a->pushMessageToSingle($content, input('get.title'), $text, input('get.code'), 2);
        dump($rep);
    }

    function demoInfo()
    {
        $redis = new Redis();
        dump($redis->hGetJson('memberInfo', input('get.code')));
    }


    function demos()
    {
        $sms = new SmsCode();
        $a = $sms->smsCode(input('get.phone'));
        dump($a);
        die;
        $a = new IGeTuiService();
        $content = '这是哪里?';
        $title = '红包来了';
        $text = '这是消息内容';
        $code = 'gb340177';
        $rep = $a->pushMessageToSingle($content, input('get.title'), $text, input('get.code'));
        dump($rep);
    }

    function IGtTransmissionTemplateDemo()
    {
        $template = new \IGtTransmissionTemplate();
        $template->set_appId(APPID);//应用appid
        $template->set_appkey(APPKEY);//应用appkey
        $template->set_transmissionType(1);//透传消息类型
        $template->set_transmissionContent("测试离线ddd");//透传内容
        //$template->set_duration(BEGINTIME,ENDTIME); //设置ANDROID客户端在此时间区间内展示消息
        //APN简单推送
//        $template = new IGtAPNTemplate();
//        $apn = new IGtAPNPayload();
//        $alertmsg=new SimpleAlertMsg();
//        $alertmsg->alertMsg="";
//        $apn->alertMsg=$alertmsg;
////        $apn->badge=2;
////        $apn->sound="";
//        $apn->add_customMsg("payload","payload");
//        $apn->contentAvailable=1;
//        $apn->category="ACTIONABLE";
//        $template->set_apnInfo($apn);
//        $message = new IGtSingleMessage();

        //第三方厂商推送透传消息带通知处理
        $notify = new \IGtNotify();
        $notify->set_payload("{}");
        $notify->set_title("透传通知标题");
        $notify->set_content("透传通知内容");
        $notify->set_type(\NotifyInfo_Type::_payload);
        $template->set3rdNotifyInfo($notify);

        //APN高级推送
        $apn = new \IGtAPNPayload();
        $alertmsg = new \DictionaryAlertMsg();
        $alertmsg->body = "";
        $alertmsg->actionLocKey = "";
        $alertmsg->locKey = "";
        $alertmsg->locArgs = array("");
        $alertmsg->launchImage = "";
//        IOS8.2 支持
        $alertmsg->title = "";
        $alertmsg->titleLocKey = "";
        $alertmsg->titleLocArgs = array("");

        $alertmsg->subtitle = "subtitle";

        $apn->alertMsg = $alertmsg;
        $apn->badge = 7;
        $apn->sound = "";
        $apn->add_customMsg("payload", "");
        $apn->voicePlayType = 1;
        $apn->contentAvailable = 1;
        $apn->category = "ACTIONABLE";

        //IOS多媒体消息处理
        $media = new \IGtMultiMedia();
        $media->set_url("");
        $media->set_onlywifi(false);
        $media->set_type(\MediaType::pic);

        $medias = array();
        $medias[] = $media;
        //$apn->set_multiMedias($medias);

        $template->set_apnInfo($apn);

        //PushApn老方式传参
//    $template = new IGtAPNTemplate();
//          $template->set_pushInfo("", 10, "", "com.gexin.ios.silence", "", "", "", "");

        return $template;
    }

    function openApp()
    {
        return $this->fetch('/login/demo');
    }

    function getAge()
    {
        $id = input('get.id');
        dump(getAge($id));
    }
}